# import asyncio
# import time
#
#
# async def say_after(delay, what):
#     await asyncio.sleep(delay)
#     print(what)
#
#
# async def main():
#     async with asyncio.TaskGroup() as tg:
#         task1 = tg.create_task(
#             say_after(1, 'hello'))
#
#         task2 = tg.create_task(
#             say_after(2, 'world'))
#
#         print(f"started at {time.strftime('%X')}")
#
#     print(f"finished at {time.strftime('%X')}")
#
#
# asyncio.run(main())


import asyncio


# 定义一个普通的同步函数 a
def a():
    print("Starting task...")
    import time
    time.sleep(5)  # 模拟耗时操作
    print("Task completed!")


# 运行异步任务
async def main():
    await asyncio.to_thread(a)  # 在后台线程中异步执行同步函数 a


# 启动事件循环
asyncio.run(main())
